﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using HigLabo.Net;

namespace HigLabo.WindowsAzure.RestService.ServiceManagement
{
    public class GetDeploymentCommand : ManagementServiceCommand<GetDeploymentResult>
    {
        /// <summary>
        /// 対象サービス名
        /// </summary>
        public String ServiceName { get; private set; }

        /// <summary>
        /// デプロイメント名
        /// </summary>
        public String Name { get; private set; }

        /// <summary>
        /// デプロイメントのスロット
        /// </summary>
        public DeploymentSlot? Slot { get; private set; }

        public GetDeploymentCommand(String serviceName, DeploymentSlot slot)
        {
            if (String.IsNullOrEmpty(serviceName))
            {
                throw new ArgumentException("serviceName must not be null", "serviceName");
            }
            this.ServiceName = serviceName;
            this.Slot = slot;
        }
        public GetDeploymentCommand(String serviceName, String deploymentName)
        {
            if (String.IsNullOrEmpty(serviceName))
            {
                throw new ArgumentException("serviceName must not be null", "serviceName");
            }
            if (String.IsNullOrEmpty(deploymentName))
            {
                throw new ArgumentException("deploymentName must not be null", "deploymentName");
            }
            this.ServiceName = serviceName;
            this.Name = deploymentName;
        }
        public override string GetRequestUri()
        {
            if (this.Slot.HasValue)
            {
                var slt = "";
                switch (this.Slot)
                {
                    case DeploymentSlot.Staging:
                        slt = "staging";
                        break;
                    case DeploymentSlot.Production:
                        slt = "production";
                        break;
                    default:
                        throw new NotImplementedException("DeploymentSlot");
                }
                return String.Format("services/hostedservices/{0}/deploymentslots/{1}", this.ServiceName, slt);
            }
            return String.Format("services/hostedservices/{0}/deployments/{1}", this.ServiceName, this.Name);
        }

        public override HttpMethodName MethodName
        {
            get { return HttpMethodName.Get; }
        }

        public override Dictionary<String, String> GetRequestHeaders()
        {
            return null;
        }

        public override System.IO.Stream GetRequestBodyStream()
        {
            return null;
        }

    }
}
